﻿#ifndef IOSTREAM_OPENCV_H
#define IOSTREAM_OPENCV_H

#include <iostream>
#include <string>
#include <opencv2/core.hpp>

inline std::ostream & operator<<(std::ostream & dbg, const cv::Size &size)
{
    dbg << "Size( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::Size2f &size)
{
    dbg << "Size2f( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::Size2d &size)
{
    dbg << "Size2d( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::Size2l &size)
{
    dbg << "Size2l( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::Point2f &p)
{
    dbg << "Point2f(" << p.x << ", " << p.y << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::Point2i &p)
{
    dbg << "Point2i(" << p.x << ", " << p.y << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::Point2d &p)
{
    dbg << "Point2d(" << p.x << ", " << p.y << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::Rect &rect)
{
    dbg << "Rect( (x, y) = (" << rect.x << "," << rect.y << "), width = " << rect.width << ", height = " << rect.height << ")";
    return dbg;
}

inline std::ostream & operator<<(std::ostream & dbg, const cv::RotatedRect &rrt)
{
    dbg << "RotatedRect(center = " << rrt.center << ", Size = " << rrt.size << ", angle = " << rrt.angle << ")";
    return dbg;
}

inline std::string Msg(const cv::Mat &mat)
{
    std::string depth;
    switch(mat.depth())
    {
        case CV_8U: depth = "CV_8U"; break;
        case CV_8S: depth = "CV_8S"; break;
        case CV_16U: depth = "CV_16U"; break;
        case CV_16S: depth = "CV_16S"; break;
        case CV_16F: depth = "CV_16F"; break;
        case CV_32S: depth = "CV_32S"; break;
        case CV_32F: depth = "CV_32F"; break;
    }
    //std::string msg;
    std::stringstream s;
    s << "Mat(" << mat.size() << ", depth = " << depth  << ", channel = " << mat.channels() << ")";
    return s.str();
}

//inline std::ostream & operator<<(std::ostream & dbg, const cv::Mat &mat)
//{
//    std::string depth;
//    switch(mat.depth())
//    {
//        case CV_8U: depth = "CV_8U"; break;
//        case CV_8S: depth = "CV_8S"; break;
//        case CV_16U: depth = "CV_16U"; break;
//        case CV_16S: depth = "CV_16S"; break;
//        case CV_16F: depth = "CV_16F"; break;
//        case CV_32S: depth = "CV_32S"; break;
//        case CV_32F: depth = "CV_32F"; break;
//    }
//    dbg << "Mat(" << mat.size() << ", depth = " << depth  << ", channel = " << mat.channels() << ")";
//    return dbg;
//}
#endif // IOSTREAM_OPENCV_H
